<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>
<script>
    document.cookie = "name=张三; expires=" + new Date(new Date().getTime() + 3 * 60 * 1000)
    document.cookie = 'age=30'
    document.cookie = 'sex=true'
    function getcookie(key) {
        let str = document.cookie
        //创建一个空对象来保存zhi
        let obj = {}
        //通过； 用split分割成数组，
        let str1 = str.split('; ')
        //遍历str1数组
        str1.forEach(item => {
            let str1 = item.split('=')
            obj[str1[0]] = str1[1]
        });
        return obj[key]
    }
    console.log(getcookie('name'))
    console.log(getcookie('age'))
</script>